package com.hnichr.ump.common.util;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.RandomUtil;

import java.util.Date;

/**
 * 生成工具类
 */
public class GenerateUtils {

    /**
     * 优惠码的基础字符串
     */
    private static final String discountCodeBaseStr = "ABCDEFGHJKMNPQRSTUVWXY3456789";

    /**
     * 订单号的随机位数
     */
    private static final int orderNoRandomCount = 5;

    /**
     * 订单号构成，共21位：1位业务类型 + yyMMddHHmmss + 3位随机数 + SSS + 2位随机数
     * @return
     */
    public static String getOrderNo() {
        String timeStr = DateUtil.format(new Date(), "yyMMddHHmmssSSS");
        String timeStr1 = timeStr.substring(0, 12);
        String timeStr2 = timeStr.substring(12);
        String randomStr = RandomUtil.randomString(discountCodeBaseStr, orderNoRandomCount);
        String randomStr1 = randomStr.substring(0, 3);
        String randomStr2 = randomStr.substring(3);
        return "D" + timeStr1 + randomStr1 + timeStr2 + randomStr2;
    }

}
